package com.ruoyi.web.controller.shelves;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.shelves.domain.Tooltype;
import com.ruoyi.shelves.service.ITooltypeService;

/**
 * 工具类型Controller
 *
 * @author ruoyi
 * @date 2021-12-02
 */
@RestController
@RequestMapping("/tooltype/tooltype")
public class TooltypeController extends BaseController
{
    @Autowired
    private ITooltypeService tooltypeService;

    /**
     * 查询工具类型列表
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tooltype tooltype)
    {
        startPage();
        List<Tooltype> list = tooltypeService.selectTooltypeList(tooltype);
        return getDataTable(list);
    }

    /**
     * 导出工具类型列表
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:export')")
    @Log(title = "工具类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tooltype tooltype)
    {
        List<Tooltype> list = tooltypeService.selectTooltypeList(tooltype);
        ExcelUtil<Tooltype> util = new ExcelUtil<Tooltype>(Tooltype.class);
        util.exportExcel(response, list, "工具类型数据");
    }

    /**
     * 获取工具类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tooltypeService.selectTooltypeById(id));
    }

    /**
     * 新增工具类型
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:add')")
    @Log(title = "工具类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tooltype tooltype)
    {
        return toAjax(tooltypeService.insertTooltype(tooltype));
    }

    /**
     * 修改工具类型
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:edit')")
    @Log(title = "工具类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tooltype tooltype)
    {
        return toAjax(tooltypeService.updateTooltype(tooltype));
    }

    /**
     * 删除工具类型
     */
    @PreAuthorize("@ss.hasPermi('tooltype:tooltype:remove')")
    @Log(title = "工具类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tooltypeService.deleteTooltypeByIds(ids));
    }
}
